import os
import sys
import struct

name = "rtthread-loader"

path = os.path.join(sys.path[0], name+".bin")
f_size = os.path.getsize(path)
print(f_size)

row_bytes = 4


with open(path, "rb") as f:
    with open(os.path.join(sys.path[0], name+"_bin2hex.txt"), "w") as f_w:
        data = f.read(row_bytes)
        while data:
            if(len(data) < row_bytes):
                print(data)
                data = data + (row_bytes-len(data))*b"\0"
            data = struct.unpack("I", data)[0]
            data = str(hex(data))[2:]
            data = (row_bytes*2-len(data))*'0' + data

            f_w.write(data+"\n")

            data = f.read(row_bytes)
    
